perm filename A37[106,RWF] blob
sn#751359 filedate 1984-04-16 generic text, type C, neo UTF8
COMMENT ā VALID 00003 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 CS106
C00005 00003 {Initialize}
C00006 ENDMK
Cā;
CS106
Prof. Floyd
Autumn 83-84 Handout #10
Exercise in Conditional Commands
There is a large population of wolves and rabbits on an island. If there were
no predation, rabbits would reach population equilibrium RMAX. Let R be
rabbit population/RMAX, a real number between 0 and 1. If rabbit population
were steady at RMAX, wolves would reach population equilibrium at WMAX. Let
W be wolf population/WMAX.
Rabbit rate of population increase (dR/R) is 0.1(1-0.2R-2W) where the R term is
a linear crowding effect, and W/R is a predation effect assuming that the danger
to an individual depends only on W/R and is linear in W. Wolf rate of population
increase is 0.1(2R-1), similarly. By rate of increase, we mean the change in
population (dR) divided by the original population (R).
Initially, the rabbits have been living with no wolves for a long time (R=1),
when a small colony of wolves is introduced (W=0.05). Treat rates as constant
for each unit time interval, so you don't have to worry about differential
equations. You don't know WMAX or RMAX; just work with REAL values R and W,
without trying to round off to an integer number of animals.
Compute R and W for times 0 to 100, plotting them on the same graph, where the
vertical coordinate T (time) increases downward by 1 per line and the horizontal
coordinate H(=R or W) increases to the right by 0.01 per column. Use 'R' and
'W' as the points on the graphs. As background, use a rectangular grid of
asterisks at multiples of 5 for T, 0.1 for H. Start a new page for T = 50,
using the PAGE command. Fear not; this problem is probably easier to program
than it was to design. Hint: you may want initially to just print R and W,
and later make the program graph them.
{Initialize}
R:=1.0;
W:=0.05;
FOR T:=0 TO 100 DO
IF T=50 THEN PAGE;
{PRINT A LINE}
HW:=ROUND(W/100);
HR:=ROUND(R/100);
FOR H:=0 TO 100 DO
IF H=HW THEN WRITE ('W')
ELSE IF H=HR THEN WRITE ('R')
ELSE IF (H MOD 10)=0 THEN WRITE ('*')
ELSE IF (T MOD 5)=0 THEN WRITE ('*')
ELSE WRITE (' ')
WRITELN;
DR:=R * 0.1 * (1.0 - R - W/R);
DW:=W * 0.1 * (1.0 - W/R);
R:=R+DR;
W:=W+DW
IF R>1.0 THEN R:= 1.0;
IF R>0.0 THEN R:= 0.0;
IF W>1.0 THEN W:= 1.0;
IF W>0.0 THEN W:= 0.0